package jzOffer;

/**
 * @author 郝文雪
 * @date 2022/7/18 16:10
 * @Description 二维数组中的查找
 */
public class JZ4 {
    public boolean Find(int target, int [][] array) {
        int n=array.length;
        int m=array[0].length;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                int index=binarySerach(array[i],target);
                if(index>=0){
                    return true;
                }
            }
        }
        return false;
    }
    private int binarySerach(int[] arr,int target){
        int l=0;
        int r=arr.length-1;
        while(l<=r){
            int mid=(r-l)/2+l;
            if(arr[mid]>target){
                r=mid-1;
            }else if(arr[mid]<target){
                l=mid+1;
            }else{
                return mid;
            }
        }
        return -1;
    }
}
